package com.LeetCode.Tree;

import org.junit.Test;

/**
 * 判断树的子结构
 */
public class isSubtree {

    public boolean isSubtree(TreeNode s, TreeNode t) {
        if(t == null) return true;
        if(s == null) return false;
        return isSubtree(s.left, t) || isSubtree(s.right , t) || isSameTree(s,t);
    }

    public boolean isSameTree(TreeNode s, TreeNode t){
        if(s == null && t == null) return true;
        if(s == null || t == null) return false;
        if(s.val != t.val) return false;
        return isSameTree(s.left,t.left) && isSameTree(s.right, t.right);
    }

    @Test
    public void test(){

    }
}
